﻿
using Microsoft.VisualBasic.Logging;
using Sunny.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using WinFormsApp1.Leo;
using WinFormsApp1.SuYi.Week2WinForm;
using WinFormsApp1.WangHaoQi._02Winfroms.CommonDto;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static WinFormsApp1.WangHaoQi.Week02Winfroms.CheckInShowHtml;

namespace WinFormsApp1.WangHaoQi.Week02Winfroms
{
    public partial class CheckInShowHtml : Form
    {
        public CheckInShowHtml()
        {
            InitializeComponent();
            Show();
            SupplierShow();
            SettlementTypeShow();
            comboBox3.Items.Add("请选择");
            comboBox3.Items.Add("已出场");
            comboBox3.Items.Add("未出场");
        }
        // 公开属性
        /// <summary>
        /// 起始页
        /// </summary>
        public int pageindex = 1;
        /// <summary>
        /// 页容量
        /// </summary>
        public int pagesize = 3;
        /// <summary>
        /// 总条数
        /// </summary>
        public int totalcount = 0;
        /// <summary>
        /// 总页数
        /// </summary>
        public int pagecount = 0;
        /// <summary>
        /// 进场登记时间
        /// </summary>
        public DateTime? EnterTimea = null;
        /// <summary>
        /// 供应商/养殖户 外健
        /// </summary>
        public int SupplierId = 0;
        /// <summary>
        /// 结算类型 外键
        /// </summary>
        public int SettlementTypeId = 0;
        /// <summary>
        /// 进场登记状态
        /// </summary>
        public int CheckInStateId = 0;

        private async void CheckInShowHtml_Load(object sender, EventArgs e)
        {

        }
        private async void Show()
        {
            dataGridView1.AutoGenerateColumns = false;
            var data = new CheckInShowCommand
            {
                pageindex = pageindex,
                pagesize = pagesize,
                EnterTime = EnterTimea,
                SupplierId = SupplierId,
                SettlementTypeId = SettlementTypeId,
                CheckInStateId = CheckInStateId,
            };
            
            var items = await HttpClientHelper.RequestUrl<object, ApiResultFY1<List<CheckIn>>>(URLCommon.Url2, "/CheckIn/CheckInShow", HttpClientHelper.MethodType.POST, data);
            this.dataGridView1.DataSource = items.Data.list;
            totalcount = items.Data.totalcount;
            pagecount = items.Data.pagecount;

            //分页文字显示
            label5.Text = Convert.ToString(pagecount);
            label8.Text = Convert.ToString(totalcount);
            label11.Text = Convert.ToString(pageindex);
            label14.Text = Convert.ToString(pagesize);

            //分页  页数的下拉框绑定
            List<object> list = new List<object>();
            for (var i = 1; i <= pagecount; i++)
            {
                list.Add(i);
            }
            comboBox4.DataSource = list;
            this.Controls.Add(comboBox4);
        }

        public class CheckInShowCommand
        {
            /// <summary>
            /// 起始页
            /// </summary>
            public int pageindex { get; set; }
            /// <summary>
            /// 页容量
            /// </summary>
            public int pagesize { get; set; }
            /// <summary>
            /// 进场登记时间
            /// </summary>
            public DateTime? EnterTime { get; set; }

            /// <summary>
            /// 供应商/养殖户 外健
            /// </summary>
            public int SupplierId { get; set; }
            /// <summary>
            /// 结算类型 外键
            /// </summary>
            public int SettlementTypeId { get; set; }
            /// <summary>
            /// 进场登记状态
            /// </summary>
            public int CheckInStateId { get; set; }
        }
        /// <summary>
        /// 重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton2_Click(object sender, EventArgs e)
        {
            dateTimePicker1.Text = "";
            comboBox2.Text = "请选择";
            comboBox1.Text = "请选择";
            comboBox3.Text = "请选择";
            comboBox1.SelectedValue = 0;
            comboBox2.SelectedValue = 0;
            comboBox3.SelectedValue = 0;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton1_Click(object sender, EventArgs e)
        {
            if (dateTimePicker1.Text != " ")
            {
                EnterTimea = Convert.ToDateTime(dateTimePicker1.Text);
            }
            if (comboBox1.Text != null)
            {
                SupplierId = Convert.ToInt32(comboBox1.SelectedValue);
            }
            if (comboBox2.Text != null)
            {
                SettlementTypeId = Convert.ToInt32(comboBox2.SelectedValue);
            }
            //假数据查询
            if (comboBox3.Text != null)
            {
                // MessageBox.Show(comboBox3.Text);
                if (comboBox3.Text == "已出场")
                    CheckInStateId = 2;
                if (comboBox3.Text == "未出场")
                    CheckInStateId = 1;
            }
            Show();
        }
        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton5_Click(object sender, EventArgs e)
        {
            if (pageindex != 1)
            {
                pageindex = 1;
            }
            Show();
        }
        /// <summary>
        /// 尾页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton6_Click(object sender, EventArgs e)
        {
            if (pageindex != pagecount)
            {
                pageindex = pagecount;
            }
            Show();
        }
        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton3_Click(object sender, EventArgs e)
        {
            if (pageindex > 1)
            {
                pageindex--;
            }
            else
            {
                //弹框提示
                MessageBox.Show("已经第一页了");
            }
            Show();
        }
        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton4_Click(object sender, EventArgs e)
        {
            if (pageindex < pagecount)
            {
                pageindex++;
            }
            else
            {
                //弹框提示
                MessageBox.Show("已经最后一页了");
            }
            Show();
        }
        /// <summary>
        /// 下拉框 选择跳转的页面  改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            pageindex = Convert.ToInt32(comboBox4.SelectedValue);
            Show();
        }
        /// <summary>
        /// 供应商下拉框绑定
        /// </summary>
        public async void SupplierShow()
        {
            var items = await HttpClientHelper.RequestUrl<object, ApiResult<List<Suppliers>>>(URLCommon.Url2, "/CheckIn/SupplierShow", HttpClientHelper.MethodType.POST, null);
            comboBox1.DataSource = items.Data;
            comboBox1.DisplayMember = "SupplierName";
            comboBox1.ValueMember = "SupplierId";

            this.Controls.Add(comboBox1);
        }
        /// <summary>
        /// 供应商
        /// </summary>
        public class Suppliers
        {
            public int SupplierId { get; set; }
            public string SupplierName { get; set; }
        }
        /// <summary>
        /// 进场类型下拉框绑定
        /// </summary>
        public async void SettlementTypeShow()
        {
            var items = await HttpClientHelper.RequestUrl<object, ApiResult<List<SettlementType>>>(URLCommon.Url2, "/CheckIn/SettlementTypeShow", HttpClientHelper.MethodType.POST, null);
            comboBox2.DataSource = items.Data;
            comboBox2.DisplayMember = "SettlementTypeName";
            comboBox2.ValueMember = "SettlementTypeId";

            this.Controls.Add(comboBox2);
        }

        /// <summary>
        /// 进场类型
        /// </summary>
        public class SettlementType
        {
            public int SettlementTypeId { get; set; }
            public string SettlementTypeName { get; set; }
        }
        /// <summary>
        /// 进场登记
        /// </summary>
        public class CheckIn
        {
            /// <summary>
            /// 进场登记id
            /// </summary>
            public int CheckInId { get; set; }
            /// <summary>
            /// 进场登记编号
            /// </summary>
            public string CheckInNo { get; set; }
            /// <summary>
            /// 时间
            /// </summary>
            public DateTime EnterTime { get; set; }
            /// <summary>
            /// 进场登记时间
            /// </summary>
            public DateTime EnterTime1 { get; set; }
            /// <summary>
            /// 出场时间
            /// </summary>
            public DateTime GoOutTime { get; set; }
            /// <summary>
            /// 车牌号
            /// </summary>
            public string CarNo { get; set; }
            /// <summary>
            /// 供应商/养殖户 外健
            /// </summary>
           // public int SupplierId { get; set; }
            /// <summary>
            /// 结算类型 外键
            /// </summary>
           // public int SettlementTypeId { get; set; }
            /// <summary>
            /// 进场数量
            /// </summary>
            public int ApproachNum { get; set; }
            /// <summary>
            /// 检疫证号
            /// </summary>
            public string QuarantineNo { get; set; }
            /// <summary>
            /// 产地
            /// </summary>
            public string OriginAddr { get; set; }
            /// <summary>
            /// 进场批次
            /// </summary>
            public string CheckInBatch { get; set; }
            /// <summary>
            /// 送货联系人
            /// </summary>
            public string Deliveryman { get; set; }
            /// <summary>
            /// 联系电话
            /// </summary>
            public string Phone { get; set; }
            /// <summary>
            /// 身份证
            /// </summary>
            public string IdentityCard { get; set; }
            /// <summary>
            /// 进场登记员
            /// </summary>
            public string EnterRegistrar { get; set; }
            /// <summary>
            /// 出场登记员
            /// </summary>
            public string GoOutRegistrar { get; set; }
            /// <summary>
            /// 检疫证（图片）    上传
            /// </summary>
            //public string QuarantineImg { get; set; }
            /// <summary>
            /// 进场登记状态
            /// </summary>
           // public int CheckInStateId { get; set; }
            /// <summary>
            /// 备注
            /// </summary>
            public string Remark { get; set; }
            /// <summary>
            /// 供应商 名称
            /// </summary>
            public string SupplierName { get; set; }
            /// <summary>
            /// 进场状态 名称
            /// </summary>
            public string CheckInStateName { get; set; }
            /// <summary>
            /// 结算类型 名称
            /// </summary>
            public string SettlementTypeName { get; set; }
        }
        /// <summary>
        /// 获取进场登记的编号 然后跳转到新增页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            CheckInNoSelect.CheckInNo = dataGridView1.Rows[e.RowIndex].Cells["CheckInNo"].Value.ToString();
            LiveAnimalsAddHtml liveAnimalsAddHtml = new LiveAnimalsAddHtml();
            //显示活畜新增页面
            liveAnimalsAddHtml.Show();
        }
    }
}
